package org.tczs93.springsecurity.config.exception;


import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 * @author TaoerLi
 *
 */

import java.util.HashMap;
import java.util.Map;

/**
 * 全局异常处理
 * @author tao.li
 *
 */
@ControllerAdvice
public class GlobalExceptionHandler {
	
	@ExceptionHandler({CustomerException.class, BadCredentialsException.class, InternalAuthenticationServiceException.class})
    @ResponseBody
    public Map<String,Object> customerExceptionHandler(Exception exception) throws Exception {

		Map<String,Object> map = new HashMap<>();
		map.put("code",999);
		map.put("message",exception.getMessage());
		
        return map;
    }
	
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Map<String,Object> globalExceptionHandler(Exception exception) throws Exception {

		Map<String,Object> map = new HashMap<>();
		map.put("code",555);
		map.put("message",exception.getMessage());

		return map;
    }
    
}
